package cn.jia.spring4;

/**
 * Created by jia on 2018/4/3.
 */

import cn.jia.spring2.pojo.InterfaceImpl.BlankDisc;
import cn.jia.spring2.pojo.myInterface.CompactDisc;
import cn.jia.spring4.annotation.BlankAnnotation;
import cn.jia.spring4.aspect.Inform.Encoreable;
import cn.jia.spring4.target.Performance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.lang.annotation.Retention;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring-context4.xml"})
public class Test3 {
    @Resource
    private Performance performance;
    @Resource
    @BlankAnnotation
    private CompactDisc compactDisc;
    @Test
    public void test(){
        performance.perform();
        System.out.println();
    }

    /**
     * 为目标类传参
     */
    @Test
    public void test2(){
        compactDisc.playTrack(0,0);
        System.out.println();
    }

    /**
     * 为目标类添加新功能，使用xml配置方法
     */
    @Test
    public void test3(){
        //目标类为performance
        performance.perform();
        //将目标类强制类型转换为代理类，委托类
        Encoreable encoreable = (Encoreable) performance;
        encoreable.performEncore();
    }

    /**
     * 测试使用AspectJ
     */
    @Test
    public void test4(){
        performance.perform();
        System.out.println();
    }
}
